<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title">
  <legend>头像图片</legend>	
  <div class="layui-field-box">
		<button type="button" class="layui-btn" id="test1">
		<i class="layui-icon">&#xe67c;</i>上传图片
		 </button>
		 <table class="layui-table">
		 	<thead>
	 			<tr>
	 				<td>文件名</td>
	 				<td>图片</td>
	 				<td>操作</td>
		 		</tr>
		 	</thead>
		 	<tbody>
		 	</tbody>
		 </table>
  </div>
</fieldset>
<script type="text/javascript">
var code='<%= request.getParameter("code") %>';


function init(){
	
	ajax('/EmployeeServlet',{action:'get',code:code},'json',function(data){
		
		var image=data.image;	
		if(image) showPic(image);
		else $("tbody").html('');
	})
}
init();
function showPic(image){
	var html="<tr><td>"+image
	+"</td><td><img src='/temp/"+image+"' class='layui-upload-img' >"
	+"</td><td><input type='button' onclick='delPic()' class='layui-btn' value='删除'>"
	+"</td>"+"</tr>";
	$("tbody").html(html);
}
renderUpload("test1","/EmployeeUploadServlet",{code:code},function(res){
	
	if(res.code==1){
		layer.msg("上传成功");
	}else
		layer.msg("上传失败");
})
function delPic(){
	layerConfirm(function () {
        ajax("/EmployeeServlet", {action: "delPic", code: code}, 'text', function (data) {
             if(data==1)
            	 {layer.msg("删除成功");
            	 $("tbody").html('');}
            }
        )
    },"是否确定删除头像")
}
</script>
</body>
</html>